package com.sky.controller.admin;

import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("Adminmeal")
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐管理")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @PostMapping("")
    @ApiOperation("添加套餐")
    @CacheEvict(cacheNames = "setcategorycach",allEntries = true)
public Result<Setmeal> addmeal(@RequestBody SetmealVO setmealVO)
{

    setmealService.add(setmealVO);

    return Result.success();
}
    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO)
    {
        log.info("查询的菜品为{}",dishPageQueryDTO);
        PageResult pageResult = setmealService.page(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    @DeleteMapping
    @ApiOperation("删除套餐")
    @CacheEvict(cacheNames = "setcategorycach",allEntries = true)
    public  Result<Setmeal> delete(@RequestParam List<Long> ids)
    {
        setmealService.delete(ids);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("套餐启用禁用")
    @CacheEvict(cacheNames = "setcategorycach",allEntries = true)
    public Result<Setmeal> setstatus(@PathVariable Integer status,Long id)
    {
        setmealService.setstatus(status,id);
        return Result.success();
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查套餐")
    public Result<SetmealVO> select(@PathVariable Long id)
    {
        SetmealVO setmealVO =  setmealService.select(id);
        return Result.success(setmealVO);
    }

    @PutMapping
    @ApiOperation("修改套餐")
    @CacheEvict(cacheNames = "setcategorycach",allEntries = true)
    public Result<Setmeal> update(@RequestBody SetmealVO setmealVO)
    {
        setmealService.update(setmealVO);
        return Result.success();
    }

}
